﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Common;


namespace GPCSC.Web.QJQ
{
    public partial class QJQEdit : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string type = Usual.f_querystringToString("type");
                if (type == "edit")
                {
                    get_data();
                }
            }

        }
        protected void get_data()
        {
            base.o_uiTable.Clear();
            base.o_uiTable.Add("@Row_id", Usual.f_querystringToString("id"));
            DataSet ds = new SqlReadXml().ReaderDataSet("select_CL_QJQ_byid", base.o_uiTable);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    UIFactory.UIFactory_Set(this, ds.Tables[0]);
                    years.Value = ds.Tables[0].Rows[0]["years"].ToString() + "-" + ds.Tables[0].Rows[0]["months"].ToString();

                }
            }
        }

        //保存
        protected void Button1_Click(object sender, EventArgs e)
        {
            
            try
            {
                string type = Usual.f_querystringToString("type");
                Model.CL_USER_S user = reuser();
                DateTime dt =  Usual.f_convertDateTime(years.Value);
                DateTime dt2 = dt.AddMonths(1).AddDays(-1);
                Hashtable htbale = new Hashtable();
                htbale = f_getElements();
                htbale.Add("Postid",user.CL_POSTID_PK.ToString());
                htbale.Add("PostName", user.POSTName);

                htbale.Add("adddate", DateTime.Now);
                htbale.Add("R_date", dt2);
                htbale.Add("years", dt2.Year);
                htbale.Add("months", dt2.Month);
                
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                if (type == "add")
                {
                    dtable.databyhtables(htbale, "add", "CL_QJQ", "Row_id", "");
                }
                else
                {
                    dtable.databyhtables(htbale, "update", "CL_QJQ", "Row_id", Usual.f_querystringToString("id"));
                }

                Response.Write("<script>alert('保存成功');window.location.href='QJQList.aspx'</script>");
                    
                
            }
            catch (Exception ex)
            {
                string message = ex.Message;

                message = message.Replace("'", "");
                message = message.Replace("\"", "");
                message = message.Replace("\n", @"\n").Replace("\r", @"\r").Replace("\"", @"\""");
                Response.Write("<script>alert('"+message+"');window.location.href='QJQList.aspx'</script>"); 

            }
        }
        public Hashtable f_getElements()
        {

            base.o_uiTable.Clear();
            base.o_uiTable = UIFactory.UIFactory_Get(this);
            return base.o_uiTable;
        }
        protected Model.CL_USER_S reuser()
        {
            byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
            Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
            Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
            return users;

        }

    }
}